home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 22 / Amiga Format AFCD22 (Jan 1998, Issue 106).iso / -in_the_mag- / converters / graphics / netpbm / hpcdtoppm.0.6 / src / hpcdtoppm.h < prev    next >
C/C++ Source or Header  |  1997-11-16  |  6KB  |  250 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. /* #include <malloc.h> */ /* not needed on the Amiga */
  15. #include <sys/types.h>
  16. #include <ctype.h>
  17. #include "config.h"
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. /* Format definitions */
  27.  
  28. #define BaseW ((dim)768)
  29. #define BaseH ((dim)512)
  30.  
  31. #define SECSIZE 0x800
  32.  
  33. #define SeHead   2
  34. #define L_Head   (1+SeHead)
  35.  
  36. #define SeBase16 18
  37. #define L_Base16 (1+SeBase16)
  38.  
  39. #define SeBase4  72
  40. #define L_Base4  (1+SeBase4)
  41.  
  42. #define SeBase   288
  43. #define L_Base   (1+SeBase)
  44.  
  45.  
  46. #define neutrLum 128
  47. #define neutrCh1 156
  48. #define neutrCh2 137
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. /* Structures and definitions */
  57. struct _implane
  58.  {dim  mwidth,mheight,
  59.        iwidth,iheight;
  60.   uBYTE *im,*mp;
  61.  };
  62. typedef struct _implane implane;
  63.  
  64. #define nullplane ((implane *) 0)
  65.  
  66.  
  67.  
  68.  
  69.  
  70. struct _sizeinfo
  71.  {dim w,h;  /* Image Resolution */
  72.   dim rdhoff,rdhlen, rdvoff, rdvlen; /* Size of Image in Memory */
  73.   dim imhoff,imhlen, imvoff, imvlen; /* Real Size of Image */
  74.  };
  75. typedef struct _sizeinfo sizeinfo;
  76.  
  77.  
  78.  
  79.  
  80. /* Definitions for 64Base */
  81.  
  82. struct file32 { uBYTE x1,x2,x3,x4;};
  83. struct file16 { uBYTE x1,x2;};
  84. #define FILE32(x) ( (((uINT)x.x1)<<24) | (((uINT)x.x2)<<16) | (((uINT)x.x3)<<8) | (uINT)x.x4 )
  85. #define FILE16(x) ( (((uINT)x.x1)<<8) | (uINT)x.x2 )
  86.  
  87. struct ic_header {char ic_name[0x28];
  88.                   struct file16 val1;
  89.                   struct file16 val2;
  90.                   struct file32 off_descr;
  91.                   struct file32 off_fnames;
  92.                   struct file32 off_pointers;
  93.                   struct file32 off_huffman;
  94.                  };
  95.  
  96. struct ic_descr {struct file16 len;
  97.                  uBYTE  color;
  98.                  uBYTE  fill;  /* Don't know */
  99.                  struct file16 width;
  100.                  struct file16 height;
  101.                  struct file16 offset;
  102.                  struct file32 length;
  103.                  struct file32 off_pointers;
  104.                  struct file32 off_huffman;
  105.                 };
  106.  
  107.  
  108. struct ic_fname  {char fname[12];
  109.                   struct file32 size;
  110.                  };
  111.  
  112. struct ic_entry {struct file16 fno;
  113.                  struct file32 offset;
  114.                 };
  115.  
  116.  
  117.  
  118. enum   TURNS  { T_UNSPEC,T_NONE,T_RIGHT,T_LEFT,T_HEAD,T_AUTO };
  119. enum   SIZES  { S_UNSPEC,S_Base16,S_Base4,S_Base,S_4Base,S_16Base,S_64Base,S_Over,S_Contact };
  120. enum   OUTFOR { O_UNSPEC,O_PPM,O_PGM,O_YCC,O_PS,O_EPS,O_PSG,O_EPSG,O_PSD,O_EPSD,O_JPEG };
  121. enum   CORR   { C_UNSPEC,C_LINEAR,C_DARK,C_BRIGHT };
  122.  
  123. enum   ERRORS { E_NONE,E_READ,E_WRITE,E_INTERN,E_ARG,E_OPT,E_MEM,E_HUFF,
  124.                 E_SEQ,E_SEQ1,E_SEQ2,E_SEQ3,E_SEQ4,E_SEQ5,E_SEQ6,E_SEQ7,E_POS,E_IMP,E_OVSKIP,
  125.                 E_TAUTO,E_TCANT,E_SUBR,E_PRPAR,E_CONFIG,E_FOPEN };
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /**** Macros ****/
  132.  
  133.  
  134.  
  135. #ifdef DEBUG
  136. #define RPRINT  {fprintf(stderr,"R-Position %x\n",bufpos);}
  137. #else
  138. #define RPRINT
  139. #endif
  140.  
  141. #define melde(x) {if (do_melde) fprintf(stderr,x);}
  142.  
  143.  
  144. #define READBUF   READ(sbuffer,sizeof(sbuffer))
  145. #define EREADBUF {if(READBUF < 1) error(E_READ);}
  146.  
  147. #define SKIP(p)  { if (SKIPn(p)) error(E_READ);}
  148. #define SKIPr(p) { if (SKIPn(p)) return(E_READ);}
  149.  
  150.  
  151. #define TRIF(x,u,o,a,b,c) ((x)<(u)? (a) : ( (x)>(o)?(c):(b)  ))
  152. #define xNORM(x) x=TRIF(x,0,255,0,x,255)
  153. #define NORM(x) { if(x<0) x=0; else if (x>255) x=255;}
  154.  
  155. #ifndef MIN
  156. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  157. #endif
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. /* main.c */
  167. extern void         close_all(void);
  168.  
  169. extern char         *ppmname,*pcdname;
  170. extern sINT         do_diff,do_info,do_sharp,do_overskip,monochrome;
  171. extern sINT         do_melde,do_rep,do_crop;
  172. extern sINT         flvert,flhori;
  173. extern uBYTE        sbuffer[SECSIZE];
  174. extern enum TURNS   turn;
  175. extern enum SIZES   size;
  176. extern enum OUTFOR  outfor;
  177. extern enum CORR    corrmode;
  178.  
  179. extern void         SEEK(int);
  180. extern int          SKIPn(int);
  181. extern int          READ(uBYTE *,int);
  182. extern sINT         bufpos;
  183.  
  184.  
  185.  
  186.  
  187. /* error.c */
  188. extern void         eerror(enum ERRORS,char *, int);
  189.  
  190.  
  191. /* color.c */
  192. extern void         colconvert(sizeinfo *,implane *,implane *,implane *);
  193.  
  194. /* tools.c */
  195. extern void         clearimpl(implane *,sINT);
  196. extern void         halve(implane *);
  197. extern void         interpolate(implane *);
  198. extern sINT         Skip4Base(void);
  199. extern void         planealloc(implane *,dim,dim);
  200. extern void         pastein(implane *,dim,dim,dim,dim,implane *, enum TURNS);
  201. extern void         cropit(sizeinfo *,implane *,implane *,implane *);
  202. extern void         shrink(sizeinfo *,implane *,implane *,implane *);
  203. extern void         typecheck(void);
  204.  
  205.  
  206. /* format.c */
  207. extern void         readhqt(sINT);
  208. extern void         readhqtx(sINT);
  209. extern void         decode(sizeinfo *,int,implane *,implane *,implane *,sINT);
  210. extern void         decodex(FILE **,int tag,struct ic_descr *,sizeinfo *,int,implane *,sINT);
  211. extern enum ERRORS  readplain(sizeinfo *,int,implane *,implane *,implane *);
  212.  
  213.  
  214.  
  215.  
  216.  
  217. /* Type definitions for output format drives, used in output.c and the drivers */
  218.  
  219. typedef void (OUT1PL)(FILE *,dim,dim, uBYTE *,sdim,sdim);
  220. typedef void (OUT3PL)(FILE *,dim,dim, uBYTE *,sdim,sdim, uBYTE *,sdim,sdim, uBYTE *,sdim,sdim); 
  221.  
  222. /* output.c */
  223. extern void         writepicture(FILE *,sizeinfo *,implane *,implane *,implane *,enum TURNS);
  224. extern void         druckeid(void);
  225.  
  226.  
  227. /* ppm.c */
  228. extern OUT3PL       write_ppm;
  229. extern OUT1PL       write_pgm;
  230.  
  231. /* postscr.c */
  232. extern OUT3PL       write_epsrgb,write_psrgb;
  233. extern OUT1PL       write_epsgrey,write_psgrey,write_epsdith,write_psdith;
  234.  
  235. extern FLTPT        PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT,PRINTER_XDPI,PRINTER_YDPI,PRINTER_FAK;
  236. extern sINT         PSIZE_SET,DPI_SET,FAK_SET;
  237.  
  238. /* jpeg.c */
  239. extern OUT3PL        write_jpeg;
  240. extern FLTPT        JPEG_QUALITY;
  241. extern sINT        QUALITY_SET;
  242. extern FLTPT        JPEG_MAXMEMORY;
  243. extern sINT         MAXMEMORY_SET;
  244. extern sINT         OPTIMIZE_JPEG;
  245.  
  246.  
  247.  
  248.  
  249.  
  250.